include("Libraries/Three.JS/three.min.js")
include("Libraries/Three.JS/Loaders/OBJLoader.js")
include("Libraries/Three.JS/Loaders/MTLLoader.js")
include("Libraries/Three.JS/Loaders/OBJMTLLoader.js")
include("Libraries/Three.JS/Loaders/ColladaLoader.js")
include("Libraries/Three.JS/Loaders/Collada/Animation.js")
include("Libraries/Three.JS/Loaders/Collada/AnimationHandler.js")
include("Libraries/Three.JS/Loaders/Collada/KeyFrameAnimation.js")

include("Libraries/Leap/leap-0.6.4.min.js")

include("Libraries/CANNON/cannon.min.js")
include("Libraries/CANNON/ConvexGeometry.js")
include("Libraries/CANNON/CannonDebugRenderer.js")

include("Libraries/Stats/stats.min.js")

// Engine
include("Engine/Device/LeapDevice.js")
include("Engine/Device/KinectDevice.js")

include("Engine/Input/Key.js")
include("Engine/Input/Keyboard.js")
include("Engine/Input/Mouse.js")

include("Engine/Core/Animation/Joint.js")
include("Engine/Core/Animation/Skeleton.js")

include("Engine/Core/Program.js")
include("Engine/Core/Level.js")

include("Engine/Core/Elements/Element.js")
include("Engine/Core/Elements/Script.js")
include("Engine/Core/Elements/PointLight.js")
include("Engine/Core/Elements/SpotLight.js")
include("Engine/Core/Elements/AmbientLight.js")
include("Engine/Core/Elements/DirectionalLight.js")

function Engine() {}

Engine.initialise = (main) => {
  Engine.canvas = document.getElementById("canvas")

  Keyboard.initialise()
  Mouse.initialise()

  Engine.main = main
  Engine.main.initialise(Engine.canvas)

  Engine.deltaTime = 0
  Engine.time = Date.now()

  Engine.loop()
}

Engine.loadMain = (main) => {
  Engine.main = main
  Engine.main.initialise(Engine.canvas)
}

Engine.showStats = (v) => {
  if (v) {
    Engine.stats.domElement.style.visibility = "visible"
  } else {
    Engine.stats.domElement.style.visibility = hidden
  }
}

Engine.loop = () => {
  requestAnimationFrame(Engine.loop)

  Mouse.update()

  Engine.deltaTime = Date.now() - Engine.time
  Engine.time += Engine.deltaTime

  Engine.main.update()
  Engine.main.draw()
}

Engine.resize = () => {
  Engine.canvas = document.getElementById("canvas")
  Engine.main.resize(Engine.canvas)
}

function include(file) {
  	document.write('<script type="text/javascript" src="'+ file + '"></script>')
}
